//
//  WZMainTabBarController.m
//  weibo
//
//  Created by mac on 16/2/25.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "WZMainTabBarController.h"
#import "WZHomeVC.h"
#import "WZFinderVC.h"
#import "WZMessageVC.h"
#import "WZSettingVC.h"
#import "WZTabBar.h"
@interface WZMainTabBarController ()

@end

@implementation WZMainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    [self setTabbar];
    [self addChildVC];
}


/**
 *   添加子控制器
 */
- (void)addChildVC:(UIViewController *)viewController andTitle:(NSString *)title andImage:(NSString *)image andSelectedImage:(NSString *)selectedImage{
    
//    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewController];
//    viewController.title = title;
//    viewController.tabBarItem.image = [UIImage imageNamed:image];
//    viewController.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
//    
//    [self addChildViewController:nav];
    
    viewController.title = title;
    viewController.tabBarController.tabBar.tintColor = [UIColor orangeColor];
    
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewController];
    
    viewController.tabBarItem.image = [UIImage imageNamed:image];
    viewController.tabBarItem.selectedImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",image]];
    
    [self addChildViewController:nav];

}



-(void)setTabbar{
//    自定义tabbar
    WZTabBar *tabbar = [[WZTabBar alloc]initWithFrame:self.tabBar.frame];
    
    [self setValue:tabbar forKey:@"tabBar"];
//    设置tabbar的中间按钮的点击事件
    [tabbar.btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
}
-(void)btnClick{
    NSLog(@"点击我了");
}

-(void)addChildVC{


    [self setChildrenVC:[[WZHomeVC alloc]init] andTile:@"首页" andImageName:@"tabbar_home"];
    [self setChildrenVC:[[WZMessageVC alloc]init] andTile:@"消息" andImageName:@"tabbar_message_center"];
    [self setChildrenVC:[[WZFinderVC alloc]init] andTile:@"搜索" andImageName:@"tabbar_discover"];
    [self setChildrenVC:[[WZSettingVC alloc]init] andTile:@"设置" andImageName:@"tabbar_profile"];
    
}
-(void)setChildrenVC:(WZBaseTableViewController *)childrenVC andTile:(NSString *)title andImageName:(NSString *)imageName{
    
    childrenVC.title = title;
    childrenVC.tabBarController.tabBar.tintColor = [UIColor orangeColor];
    

    
    childrenVC.tabBarItem.image = [UIImage imageNamed:imageName];
    childrenVC.tabBarItem.selectedImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imageName]];
    
    [self addChildViewController:[[UINavigationController alloc]initWithRootViewController:childrenVC]];



}


@end
